package com.naizhuai.ui.task.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.naizhuai.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author：lichenxi
 * @date 2018/6/29 13
 * email：525603977@qq.com
 * Fighting
 */
public class LabelDailogAdapter extends BaseAdapter {
    private List<String> mStrings;
    private LayoutInflater mInflater;
    public LabelDailogAdapter(Context context, List<String> commonLabels) {
        mStrings = commonLabels;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mStrings.size();
    }

    @Override
    public Object getItem(int position) {
        return mStrings.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.label_dialog_item, parent, false); //加载布局
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {   //else里面说明，convertView已经被复用了，说明convertView中已经设置过tag了，即holder
            holder = (ViewHolder) convertView.getTag();
        }

        holder.value.setText(String.valueOf(position+1)+"."+mStrings.get(position));
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.value)
        TextView value;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
